//
//  NewRoomLaebl.m
//  Manager
//
//  Created by 彭凯敏 on 15/8/27.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "UIViewCategory.h"

@implementation UIViewCategory

//新建房间、价格 label
+ (void)newRoomLabel:(UILabel *)roomLabel andInfo:(RoomInfo *)info andView:(UIView *)superView
{
    UILabel *room = [[UILabel alloc]initWithFrame:roomLabel.frame];
    [room setSizeWidth:roomLabel.sizeWidth*SizeScale];
    room.lineBreakMode = NSLineBreakByWordWrapping;
    room.numberOfLines = 0;
    room.attributedText = [info.name judgeAttributeRoom:@"约看房间："];
    room.font = FontSize(14);
    [room sizeToFit];
    [superView addSubview:room];
}
+ (void)newRoomPriceLabel:(UILabel *)roomLabel andInfo:(RoomInfo *)info andView:(UIView *)superView
{
    UILabel *room = [[UILabel alloc]initWithFrame:roomLabel.frame];
    [room setSizeWidth:roomLabel.sizeWidth];
    room.lineBreakMode = NSLineBreakByWordWrapping;
    room.numberOfLines = 0;
    room.attributedText = [info.name judgeAttributeRoom:@"约看房间："];
    room.font = FontSize(14);
    [room sizeToFit];
    [superView addSubview:room];
    
    if ([room.text rangeOfString:@"无"].location != NSNotFound) {
        return;
    }
    UILabel *price = [[UILabel alloc]initWithFrame:room.frame];
    price.originX = room.originX+room.sizeWidth+8;
    price.sizeWidth = 120;
    price.font = FontSize(14);
    price.text = [NSString stringWithFormat:@"￥%d",(int)info.price];
    [superView addSubview:price];
}

+ (void)remarkLabelWith:(UILabel *)remarkLabel andText:(NSString *)text andView:(UIView *)superView
{
    UILabel *unsign = [[UILabel alloc]initWithFrame:remarkLabel.frame];
    [unsign setSizeWidth:remarkLabel.sizeWidth];
    unsign.lineBreakMode = NSLineBreakByWordWrapping;
    unsign.numberOfLines = 0;
    unsign.attributedText = [text judgeAttributeRemark:@"备       注："];
    unsign.font = FontSize(14);
    [unsign sizeToFit];
    [superView addSubview:unsign];
    
}

+ (NSString *)roomStatusWith:(RoomInfo *)info
{
    if (info.status == 4 || info.status == 5) {
        
        return [NSString stringWithFormat:@"已出租(到租时间：%@)  价格：￥%d",[KMGetDate timeFromNum:[NSString stringWithFormat:@"%llu",info.contractEndTime/1000] andFormStr:@"YYYY/MM/dd"],(int)info.price];
        
    }
    else if(info.status == 3)
    {
        return [NSString stringWithFormat:@"已预订  价格：￥%d",(int)info.price];
    }
    else if(info.status == 2)
    {
        return [NSString stringWithFormat:@"销售中  价格：￥%d",(int)info.price];
    }
    else
    {
        return [NSString stringWithFormat:@"未发布  价格：￥%d",(int)info.price];
    }
    
}

+ (CGFloat)offsetText:(UIView *)textView Height:(CGFloat )height Super:(UIScrollView *)superView
{
    CGRect rectInSuperview = [superView convertRect:textView.frame toView:[superView superview]];
    
    DLog(@"%f",height);
    
    CGFloat judgeY = rectInSuperview.origin.y+textView.sizeHeight+height - superView.sizeHeight +5;
    
    CGFloat offset = textView.originY+textView.sizeHeight + height-superView.sizeHeight+5;
    
    
    if (judgeY>0) {
        [UIView animateWithDuration:0.25 animations:^{
            
            [superView setContentOffset:CGPointMake(0, offset)];
            
        }];
    }
    
    
    return offset;
}

+ (CGFloat)loginOffsetText:(UIView *)textView Height:(CGFloat )height Super:(UIView *)superView
{
    CGRect rectInSuperview = [superView convertRect:textView.frame toView:[superView superview]];
    
    DLog(@"%f",rectInSuperview.origin.y);
    
    CGFloat offset = textView.originY+textView.sizeHeight + height-superView.sizeHeight+5;
    
    
    return offset;
}



+ (void)FailShowWith:(ErrorModel *)model
{
    if ([model.ret integerValue]== -1) {
        FailedShow(@"服务器异常");
    }
    else if ([model.ret integerValue]== -2) {
        
         FailedShow(@"protoBuf错误");
    }
    else if ([model.ret integerValue]== -3) {
        FailedShow(@"重新登录");
    }
    else if ([model.ret integerValue]== 1000) {
        FailedShow(@"网络超时");
    }
    else{
        FailedShow(model.error);
    }
    
}

//+ (void)roomWith:(NSString *)textStr withtime:(UInt64)time
//{
//    _timeLabel.text = [NSString stringWithFormat:@"%@时间：%@",textStr,[KMGetDate timeFromNum:[NSString stringWithFormat:@"%llu",_cellOrder.orderTime/1000] andFormStr:@"YYYY-MM-dd HH:mm"]];
//    
//    if (!_cellOrder.viewRooms) {
//        _roomLabel1.text = [NSString stringWithFormat:@"%@房间：无",textStr];
//        _priceLabel1.text = @"";
//    }
//    else
//    {
//        RoomInfo *info = _cellOrder.viewRooms[0];
//        _roomLabel1.text = [info.name judgeRoomBase:[NSString stringWithFormat:@"%@房间：",textStr]];
//        
//        _priceLabel1.text = [NSString stringWithFormat:@"￥%d",(int)info.price];
//        if ([info.name isEqualToString:@""]) {
//            _roomLabel1.text = [NSString stringWithFormat:@"%@时间：无",textStr];
//            _priceLabel1.text = @"";
//        }
//    }
//}
@end
